//
//  XYTabBarController.swift
//  SinaWeibo
//
//  Created by 韩啸宇 on 15/12/19.
//  Copyright © 2015年 backy. All rights reserved.
//

import UIKit

class XYTabBarController: UITabBarController {
    
    // MARK: - 懒加载属性
    private lazy var composeButton: UIButton = {
       let composeBtn = UIButton(imageName: "tabbar_compose_icon_add", backgroundImageName: "tabbar_compose_button")
        
        composeBtn.addTarget(self, action: Selector("composeClick"), forControlEvents: UIControlEvents.TouchUpInside)
        
        return composeBtn
    }()
    
    
    // MARK: - 初始化
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        // 添加加号按钮
        tabBar.addSubview(composeButton)
        
        // 计算加号按钮的位置
        let width = tabBar.bounds.size.width / CGFloat(childViewControllers.count)
        composeButton.frame.size.width = width
        composeButton.frame = CGRectOffset(composeButton.frame, width * 2, 0) // 相对于rect的x和y偏移量生成新的rect
    }
    
    // MARK: - 监听事件
    @objc private func composeClick() {
        print(__FUNCTION__)
    }

}
